#setting-up the working directory
#use the setwd function to adjust the path, for example: 
#setwd('C:/taxbase')

library(tidyverse)
gdpred <- readRDS(file = 'gdpred.rds')

theme_set(theme_bw())

#Figure 1####
#the line below and the dev.off command are only needed in order to save the figure (within Figures/PDF folder); this also applies to other figures in the analysis.
# pdf(file = 'Figures/PDF/figure1.pdf',width = 12,height = 7)
gdpred %>% ggplot(aes(x = gini_mkt, y = gini_disp,label = country_code)) +
  geom_text(size = 3) +
  geom_abline(slope = 1,alpha = 0.3) +
  facet_wrap(~group) +
  geom_hline(yintercept = 40,linetype = 'dashed',alpha = 0.3,color = 'red') +
  geom_vline(xintercept = 40,linetype = 'dashed',alpha = 0.3,color = 'blue') +
  theme(strip.text = element_text(size = 15),axis.title =  element_text(size = 14),
        axis.text = element_text(size = 11)) +
  labs(x = 'Gini index of market income', y = 'Gini index of disposable income') +
  xlim(20,75) +
  ylim(20,75)
# dev.off()

gdpineqqgroup <- gdpred %>% group_by(group) %>%
  summarise(n = n(),mktineq = mean(gini_mkt),disineq = mean(gini_disp),
            gdppc = mean(gdppc,na.rm = TRUE)) %>% ungroup()
gdpineqqgroup